home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / contrib / pdcurs22 / src / portable / inopts.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-26  |  14.2 KB  |  455 lines

  1. /*
  2. ***************************************************************************
  3. * This file comprises part of PDCurses. PDCurses is Public Domain software.
  4. * You may use this code for whatever purposes you desire. This software
  5. * is provided AS IS with NO WARRANTY whatsoever.
  6. * Should this software be used in another application, an acknowledgement
  7. * that PDCurses code is used would be appreciated, but is not mandatory.
  8. *
  9. * Any changes which you make to this software which may improve or enhance
  10. * it, should be forwarded to the current maintainer for the benefit of 
  11. * other users.
  12. *
  13. * The only restriction placed on this code is that no distribution of
  14. * modified PDCurses code be made under the PDCurses name, by anyone
  15. * other than the current maintainer.
  16. * See the file maintain.er for details of the current maintainer.
  17. ***************************************************************************
  18. */
  19. #define    CURSES_LIBRARY    1
  20. #include <curses.h>
  21.  
  22. #ifdef UNIX
  23. #define NOTLIB
  24. #include <defs.h>
  25. #include <term.h>
  26. #endif
  27.  
  28. /* undefine any macros for functions defined in this module */
  29. #undef    cbreak
  30. #undef    nocbreak
  31. #undef    echo
  32. #undef    noecho
  33. #undef    halfdelay
  34. #undef    intrflush
  35. #undef    keypad
  36. #undef    meta
  37. #undef    nodelay
  38. #undef    notimeout
  39. #undef    raw
  40. #undef    noraw
  41. #undef    noqiflush
  42. #undef    qiflush
  43. #undef    timeout
  44. #undef    wtimeout
  45. #undef    typeahead
  46.  
  47. /* undefine any macros for functions called by this module if in debug mode */
  48. #ifdef PDCDEBUG
  49. #  undef    move
  50. #  undef    wmove
  51. #endif
  52.  
  53. #ifdef PDCDEBUG
  54. char *rcsid_inopts  = "$Id$";
  55. #endif
  56.  
  57. /*man-start*********************************************************************
  58.  
  59.   Name:                                                        inopts
  60.  
  61.   Synopsis:
  62.       int cbreak(void);
  63.       int nocbreak(void);
  64.       int echo(void);
  65.       int noecho(void);
  66.   ***    int halfdelay(int tenths);
  67.       int intrflush(WINDOW *win, bool bf);
  68.       int keypad(WINDOW *win, bool bf);
  69.       int meta(WINDOW *win, bool bf);
  70.       int nodelay(WINDOW *win, bool bf);
  71.       int notimeout(WINDOW *win, bool bf);
  72.       int raw(void);
  73.       int noraw(void);
  74.   ***    void noqiflush(void);
  75.   ***    void qiflush(void);
  76.   ***    int timeout(int delay);
  77.   ***    int wtimeout(WINDOW *win, int delay);
  78.       int typeahead(int fildes);
  79.  
  80.   X/Open Description:
  81.      cbreak() and nocbreak() puts the terminal into and out of cbreak
  82.      mode. In cbreak mode, characters typed by the user are immediately
  83.      available to the program and erase/kill character processing is
  84.      not performed.  When out of cbreak mode, the terminal driver
  85.      will buffer characters typed until a newline or carriage return
  86.      is typed.  Interrupt and flow control characters are unaffected
  87.      by this mode.  Initially the terminal may or may not need be
  88.      in cbreak mode.
  89.  
  90.      echo() and noecho() control whether characters typed by the user
  91.      are echoed by the input routine.  Initially, input characters
  92.      are echoed.  Subsequent calls to echo() and noecho() do not
  93.      flush type-ahead.
  94.  
  95.      If the intrflush() option is enabled (bf is TRUE), and an interrupt
  96.      is pressed on the keyboard (INTR, BREAK, or QUIT) all output in
  97.      the terminal driver queue will be flushed, giving the effect
  98.      of faster response to the interrupt but causing curses to have
  99.      the wrong idea of what is on the screen.  Disabling the option
  100.      prevents the flush.  The default for the option is inherited
  101.      from the terminal driver settings.  The window argument is
  102.      ignored.
  103.  
  104.      The keypad() function changes the keypad option of the user's terminal.
  105.      If enabled (bf is TRUE), the user can press a function key (such
  106.      as the left arrow key) and getch() will return a single value
  107.      that represents the KEY_LEFT function key.  (See Section 11.3.3,
  108.      Input Values.)  If disabled, curses will not treat function keys
  109.      as special keys and the program has to interpret the escape
  110.      sequences itself.  If the keypad is enabled, the terminal keypad
  111.      is turned on before input begins.
  112.  
  113.      The meta() function forces the user's terminal to return 7 or 8
  114.      significant bits on input.  To force 8 bits to be returned,
  115.      invoke meta() with bf as TRUE.  To force 7 bits to be returned,
  116.      invoke meta() with bf as FALSE.
  117.      The window argument is always ignored, but it must still be a
  118.      valid window to avoid compiler errors.
  119.  
  120.      The nodelay() function controls whether wgetch() is a non-blocking
  121.      call. If the option is enabled, and no input is ready, wgetch()
  122.      will return ERR. If disabled, wgetch() will hang until input
  123.      is ready.
  124.  
  125.      While interpreting an input escape sequence, wgetch sets a timer while
  126.      waiting for the next character.  If notimeout(win,TRUE) is called, then
  127.      wgetch does not set a timer.  The purpose of the timeout is to
  128.      differentiate between sequences received from a function key and those
  129.      typed by a user.
  130.  
  131.      With raw() and noraw(), the terminal in placed into or out of raw 
  132.      mode.  Raw mode is similar to cbreak mode, in that characters typed 
  133.      are immediately passed through to the user program.  The differences
  134.      are that in raw mode, the INTR, QUIT, SUSP, and STOP characters are 
  135.      passed through without being interpreted, and without generating a
  136.      signal.  The behaviour of the BREAK key depends on other
  137.      parameters of the terminal drive that are not set by curses.
  138.  
  139.      The curses package does the "line-breakout optimisation" by
  140.      looking for type-ahead periodically while updating the screen.
  141.      If input is found, the current update will be postponed until
  142.      refresh() or doupdate() are called again.  This allows faster
  143.      response to commands typed in advance.  Normally, the input FILE
  144.      pointer passed to newterm(), or stdin in the case when initscr()
  145.      was called, will be used to do this type-ahead checking.  The
  146.      typeahead() routine specified that the file descriptor fd is to
  147.      be used to check for type-ahead instead.  If fd is -1, then no
  148.      type-ahead checking will be done.
  149.  
  150.   PDCurses Description:
  151.      The meta() function is provided for portability.  By default, 8 bits
  152.      are returned.
  153.  
  154.      notimeout() is a no-op in PDCurses.
  155.  
  156.   X/Open Return Value:
  157.      All functions return OK on success and ERR on error.
  158.  
  159.   X/Open Errors:
  160.      No errors are defined for this function.
  161.  
  162.   Portability                             X/Open    BSD    SYS V
  163.                                           Dec '88
  164.       cbreak                                Y        Y       Y
  165.       nocbreak                              Y        Y       Y
  166.       echo                                  Y        Y       Y
  167.       noecho                                Y        Y       Y
  168.       halfdelay                             Y        Y       Y
  169.       intrflush                             Y        Y       Y
  170.       keypad                                Y        Y       Y
  171.       meta                                  Y        Y       Y
  172.       nodelay                               Y        Y       Y
  173.       notimeout                             Y        Y       Y
  174.       raw                                   Y        Y       Y
  175.       noraw                                 Y        Y       Y
  176.       noqiflush                             Y        Y       Y
  177.       qiflush                               Y        Y       Y
  178.       timeout                               Y        Y       Y
  179.       wtimeout                              Y        Y       Y
  180.       typeahead                             Y        Y       Y
  181.  
  182. **man-end**********************************************************************/
  183.  
  184. /***********************************************************************/
  185. int    cbreak(void)
  186. /***********************************************************************/
  187. {
  188. #ifdef PDCDEBUG
  189.     if (trace_on) PDC_debug("cbreak() - called\n");
  190. #endif
  191.  
  192. #ifdef UNIX
  193. #ifdef USE_TERMIO
  194.     _CUR_TERM.prog_mode.c_lflag &= ~(ICANON);
  195.     _CUR_TERM.prog_mode.c_iflag &= ~(ICRNL);
  196. /*    _CUR_TERM.prog_mode.c_lflag |= ISIG;*/
  197.     _CUR_TERM.prog_mode.c_cc[VMIN] = 1;
  198.     _CUR_TERM.prog_mode.c_cc[VTIME] = 0;
  199.     ioctl(_CUR_TERM.fd, TCSETAW, &_CUR_TERM.prog_mode);
  200. #else
  201.     _CUR_TERM.prog_mode.sg_flags |= CBREAK;
  202.     ioctl(_CUR_TERM.fd, TIOCSETP, &_CUR_TERM.prog_mode);
  203. #endif
  204.  
  205. #endif
  206.  
  207.     _cursvar.cbreak = TRUE;
  208.     return( OK );
  209. }
  210. /***********************************************************************/
  211. int    nocbreak(void)
  212. /***********************************************************************/
  213. {
  214. #ifdef PDCDEBUG
  215.     if (trace_on) PDC_debug("nocbreak() - called\n");
  216. #endif
  217.  
  218. #ifdef UNIX
  219. #ifdef USE_TERMIO
  220.     _CUR_TERM.prog_mode.c_lflag |= ICANON;
  221.     ioctl(_CUR_TERM.fd, TCSETAW, &_CUR_TERM.prog_mode);
  222. #else 
  223.     _CUR_TERM->prog_mode.sg_flags &= ~CBREAK;
  224.     ioctl(_CUR_TERM.fd, TIOCSETP,&_CUR_TERM.prog_mode);
  225. #endif
  226. #endif
  227.  
  228.     _cursvar.cbreak = FALSE;
  229.     return( OK );
  230. }
  231. /***********************************************************************/
  232. int    echo(void)
  233. /***********************************************************************/
  234. {
  235. #ifdef PDCDEBUG
  236.     if (trace_on) PDC_debug("echo() - called\n");
  237. #endif
  238.  
  239. #ifdef UNIX
  240. #ifdef USE_TERMIO
  241.     _CUR_TERM.prog_mode.c_lflag |= ECHOCTL|ECHOKE;
  242.     ioctl(_CUR_TERM.fd, TCSETAW, &_CUR_TERM.prog_mode);
  243. #else
  244.     _CUR_TERM.prog_mode.sg_flags |= ECHO;
  245.     ioctl(_CUR_TERM.fd, TIOCSETP, &_CUR_TERM.prog_mode);
  246. #endif
  247. #endif
  248.  
  249.     _cursvar.echo = TRUE;
  250.     return( OK );
  251. }
  252. /***********************************************************************/
  253. int    noecho(void)
  254. /***********************************************************************/
  255. {
  256. #ifdef PDCDEBUG
  257.     if (trace_on) PDC_debug("noecho() - called\n");
  258. #endif
  259.  
  260. #ifdef UNIX
  261. #ifdef USE_TERMIO
  262.     _CUR_TERM.prog_mode.c_lflag &= ~(ECHO|ECHOPRT);
  263.     ioctl(_CUR_TERM.fd, TCSETAW, &_CUR_TERM.prog_mode);
  264. #else
  265.     _CUR_TERM.prog_mode.sg_flags &= ~ECHO;
  266.     ioctl(_CUR_TERM.fd, TIOCSETP, &_CUR_TERM.prog_mode);
  267. #endif
  268. #endif
  269.  
  270.     _cursvar.echo = FALSE;
  271.     return( OK );
  272. }
  273. /***********************************************************************/
  274. int    intrflush( WINDOW *win, bool bf )
  275. /***********************************************************************/
  276. {
  277. #ifdef    TC
  278. #  pragma argsused
  279. #endif
  280.     int    y;
  281.     int    maxy;
  282.  
  283. #ifdef PDCDEBUG
  284.     if (trace_on) PDC_debug("intrflush() - called\n");
  285. #endif
  286.  
  287.     if (win == (WINDOW *)NULL)
  288.         return( ERR );
  289.  
  290.     maxy = win->_maxy - 1;
  291.  
  292.     for (y = 0; y <= maxy; y++)
  293.     {
  294.         win->_firstch[y] = _NO_CHANGE;
  295.     }
  296.     return( OK );
  297. }
  298. /***********************************************************************/
  299. int    keypad( WINDOW *win, bool bf )
  300. /***********************************************************************/
  301. {
  302. #ifdef PDCDEBUG
  303.     if (trace_on) PDC_debug("keypad() - called\n");
  304. #endif
  305.  
  306.     win->_use_keypad = bf;
  307.     return( OK );
  308. }
  309. /***********************************************************************/
  310. int    meta( WINDOW *win, bool bf )
  311. /***********************************************************************/
  312. {
  313. #ifdef PDCDEBUG
  314.     if (trace_on) PDC_debug("meta() - called\n");
  315. #endif
  316.  
  317. #ifdef UNIX
  318. /* INCOMPLETE */
  319. #endif
  320.  
  321. #ifdef    TC
  322. # pragma argsused;
  323. #endif
  324.     _cursvar.raw_inp = bf;
  325.     return( OK );
  326. }
  327. /***********************************************************************/
  328. int    nodelay( WINDOW *win, bool flag )
  329. /***********************************************************************/
  330. {
  331. #ifdef PDCDEBUG
  332.     if (trace_on) PDC_debug("nodelay() - called\n");
  333. #endif
  334.  
  335.     win->_nodelay = flag;
  336.     return( OK );
  337. }
  338. /***********************************************************************/
  339. int    notimeout( WINDOW *win, bool flag )
  340. /***********************************************************************/
  341. {
  342. #ifdef PDCDEBUG
  343.     if (trace_on) PDC_debug("notimeout() - called\n");
  344. #endif
  345.  
  346.     return( OK );
  347. }
  348. /***********************************************************************/
  349. int    raw(void)
  350. /***********************************************************************/
  351. {
  352. #ifdef OS2
  353. # ifndef EMXVIDEO
  354.     KBDINFO KbdInfo;
  355. # endif
  356. #endif
  357.  
  358. #ifdef PDCDEBUG
  359.     if (trace_on) PDC_debug("raw() - called\n");
  360. #endif
  361.  
  362. #ifdef OS2
  363. # ifndef EMXVIDEO
  364.     KbdGetStatus(&KbdInfo,0);
  365.     KbdInfo.fsMask |= KEYBOARD_BINARY_MODE;
  366.     KbdInfo.fsMask &= ~KEYBOARD_ASCII_MODE;
  367.     KbdSetStatus(&KbdInfo,0);
  368. # endif
  369. #endif
  370.  
  371. #if defined( UNIX )    /* || defined( EMXVIDEO )    NOT COMPLETED */
  372. #ifdef USE_TERMIO
  373. #if 0
  374.     _CUR_TERM.prog_mode.c_lflag &= ~(ICANON|ISIG);
  375.     _CUR_TERM.prog_mode.c_iflag &= ~(INPCK|ISTRIP|IXON);
  376.     _CUR_TERM.prog_mode.c_oflag &= ~(OPOST);
  377.     _CUR_TERM.prog_mode.c_cc[VMIN] = 1;
  378.     _CUR_TERM.prog_mode.c_cc[VTIME] = 0;
  379.     ioctl(_CUR_TERM.fd, TCSETAW, &_CUR_TERM.prog_mode);
  380. #endif
  381.     _CUR_TERM.prog_mode.c_lflag &= ~(ICANON|ISIG);
  382.     _CUR_TERM.prog_mode.c_iflag &= ~(IXON);
  383.     _CUR_TERM.prog_mode.c_iflag |= ICRNL;
  384.     ioctl(_CUR_TERM.fd, TCSETAW, &_CUR_TERM.prog_mode);
  385. #else
  386.     _CUR_TERM.prog_mode.sg_flags |= RAW;
  387.     ioctl(_CUR_TERM.fd, TIOCSETP, &_CUR_TERM.prog_mode);
  388. #endif
  389. #endif
  390.  
  391.     _cursvar.raw_inp = TRUE;
  392.     PDC_set_ctrl_break(FALSE);      /* disallow ^BREAK on disk I/O */
  393. /*    flushinp(); */
  394.     return( OK );
  395. }
  396. /***********************************************************************/
  397. int    noraw(void)
  398. /***********************************************************************/
  399. {
  400. #ifdef OS2
  401. # ifndef EMXVIDEO
  402.     KBDINFO KbdInfo;
  403. # endif
  404. #endif
  405.  
  406. #ifdef PDCDEBUG
  407.     if (trace_on) PDC_debug("noraw() - called\n");
  408. #endif
  409.  
  410. #ifdef OS2
  411. # ifndef EMXVIDEO
  412.     KbdGetStatus(&KbdInfo,0);
  413.     KbdInfo.fsMask |= KEYBOARD_ASCII_MODE;
  414.     KbdInfo.fsMask &= ~KEYBOARD_BINARY_MODE;
  415.     KbdSetStatus(&KbdInfo,0);
  416. # endif
  417. #endif
  418.  
  419. #if defined( UNIX ) /* || defined( EMXVIDEO ) NOT COMPLETE */
  420. #ifdef USE_TERMIO
  421. #if 0
  422.     _CUR_TERM.prog_mode.c_lflag |= ISIG|ICANON;
  423.     _CUR_TERM.prog_mode.c_iflag |= IXON|INPCK|ISTRIP;
  424.     _CUR_TERM.prog_mode.c_oflag |= OPOST;
  425.     _CUR_TERM.prog_mode.c_cc[VMIN] = _CUR_TERM.shell_mode.c_cc[VMIN];
  426.     _CUR_TERM.prog_mode.c_cc[VTIME] = _CUR_TERM.shell_mode.c_cc[VTIME];
  427. #endif
  428.     _CUR_TERM.prog_mode.c_lflag |= ICANON;
  429.     ioctl(_CUR_TERM.fd, TCSETAW, &_CUR_TERM.prog_mode);
  430. #else
  431.     _CUR_TERM.prog_mode.sg_flags &= ~RAW;
  432.     ioctl(_CUR_TERM.fd, TIOCSETP, &_CUR_TERM.prog_mode);
  433. #endif
  434. #endif
  435.  
  436.     _cursvar.raw_inp = FALSE;
  437.     PDC_set_ctrl_break(TRUE);
  438.     return( OK );
  439. }
  440. /***********************************************************************/
  441. int    typeahead( int fildes )
  442. /***********************************************************************/
  443. {
  444. #ifdef PDCDEBUG
  445.     if (trace_on) PDC_debug("typeahead() - called\n");
  446. #endif
  447.  
  448.     if (fildes < 0)
  449.         _cursvar.refrbrk = FALSE;
  450.     else
  451.         _cursvar.refrbrk = TRUE;
  452.     return(OK);
  453. }
  454.